package common

import (
	"gitee.com/goddesszz/gocommon/myutil"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"monoblog/config"
	"os"
)

/*-------------------------- redis中的key或key前缀 -------------------------------*/

const REDIS_KEY_WAIT_FOR_UPDATE_BLOG = "wait-for-update-blog"

const REDIS_KEY_ChatGroup_Hash = "group-members_hash_"

const REDIS_KEY_ChatRelId_Hash = "chatRelId_hash_"

const REDIS_KEY_MOMENT_CHANNEL = "moment-channel"

// user的ws最近活跃时间
const REDIS_KEY_USER_LastTime_INDEX_PREFIX = "user-lastTime-index-"

const REDIS_VERIFY_CODE_PHONE_PREFIX = "verify-code-phone:"

/*-------------------------- 公用属性或方法 -------------------------------*/

var admin gin.Accounts

func GetAdminAccounts() gin.Accounts {
	if admin == nil {
		username := os.Getenv("ADMIN_USERNAME")
		passwd := os.Getenv("ADMIN_PASSWORD")
		if username == "" || passwd == "" {
			username = "admin"
			passwd = myutil.RandomPasswordCode(8, 1)
			logrus.Infof("生成后台管理账号 => username: %s, password: %s", username, passwd)
		}

		admin = gin.Accounts{
			username: passwd,
		}
	}
	return admin
}

var secretKeyProperties *config.SecretKeyProperties

func GetSecretKeyProperties() *config.SecretKeyProperties {
	if secretKeyProperties == nil {
		secretKeyProperties = &config.SecretKeyProperties{
			AccessSecretKey:  os.Getenv("ACCESS_SECRET_KEY"),
			RefreshSecretKey: os.Getenv("REFRESH_SECRET_KEY"),
		}
	}
	return secretKeyProperties
}

// GetLogFilePath 获取日志文件路径 日志文件名默认app.log
func GetLogFilePath() string {
	return os.Getenv("CONSOLE_LOG_PATH")
}
